import json
import unittest
import requests
from IHRM.api.login import loginAPI
from parameterized import parameterized


def build_data():
    test_data = []
    json_file = "../data/login.json"

    with open(json_file, encoding="utf-8") as f:
        json_file =json.load(f)
        for case_data in json_file:
            login_data = case_data.get("login_data")
            status_code = case_data.get("status_code")
            success = case_data.get("success")
            code = case_data.get("code")
            message = case_data.get("message")
            test_data.append((login_data, status_code, success, code, message))
            print("test_data = ", format((login_data, status_code, success, code, message)))

    return test_data
class Testlogin(unittest.TestCase):
    def setUp(self):
        self.login_api = loginAPI()
        #self.session = requests.Session()

    #def tearDown(self):
        #if self.session:
            #self.session.close()

    @parameterized.expand(build_data())
    def test01(self, login_data, status_code, success, code, message):
        port = self.login_api.login(login_data)
        print(port.json())
        self.assertEqual(status_code, port.status_code)
        self.assertEqual(success, port.json().get("success"))
        self.assertEqual(code, port.json().get("code"))
        self.assertIn(message, port.json().get("message"))